#include <cppunit/config/SourcePrefix.h>
#include "AST.h"
#include "TestAST.h"
#include <iostream>
#include <string>


void ASTTest::setUp()
{
	cout << "Test AST setUp()\n";
}
void ASTTest::tearDown()
{}
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( ASTTest ); 
// method to test the constructor
void ASTTest::testConstructor() { 
	// create a AST object
	// check that the object is constructed correctly
	AST myAST = AST::AST();
}
// method to test the assigning and retrieval of grades
void ASTTest::testCreateNodeWithTypeOnly() {
	// create a node
	AST myAST = AST::AST();
	TreeNode* node = myAST.createTreeNode(AST_PLUS);
	CPPUNIT_ASSERT(node->getNodeType() == AST_PLUS);
	
}
void ASTTest::testCreateNodeWithTypeAndContent(){
	AST myAST = AST::AST();
	TreeNode* node = myAST.createTreeNode(AST_PLUS, 1);
	CPPUNIT_ASSERT(node->getNodeType() == AST_PLUS);
	CPPUNIT_ASSERT(node->getContent() == 1);
}
void ASTTest::testSetRoot(){
	AST myAST = AST::AST();
	TreeNode* node = myAST.createTreeNode(AST_PROCEDURE);
	myAST.setRoot(node);
	CPPUNIT_ASSERT_EQUAL(node, myAST.getRoot());
}
void ASTTest::testGetRoot(){
	AST myAST = AST::AST();
	TreeNode* node = myAST.createTreeNode(AST_PROCEDURE);
	myAST.setRoot(node);
	CPPUNIT_ASSERT_EQUAL(node, myAST.getRoot());
}
void ASTTest::testLinkNodes(){
	AST myAST = AST::AST();
	TreeNode* node = myAST.createTreeNode(AST_PROCEDURE);
	myAST.setRoot(node);
	TreeNode* node2 = myAST.createTreeNode(AST_STMTLST);
	myAST.linkNodes(node,node2);
	CPPUNIT_ASSERT_EQUAL(node2,node->getChild().back());
	CPPUNIT_ASSERT_EQUAL(node,node2->getParent());
}
void ASTTest::testMatchesNodeType(){
	AST myAST = AST::AST();
	TreeNode* node = myAST.createTreeNode(AST_PROCEDURE);
	TreeNode* node2 = myAST.createTreeNode(AST_PLUS, 1);
	CPPUNIT_ASSERT(NULL != node);
	CPPUNIT_ASSERT(NULL != node2);
	CPPUNIT_ASSERT_EQUAL(true,myAST.matchesNodeType(node,AST_PROCEDURE));
	CPPUNIT_ASSERT_EQUAL(false,myAST.matchesNodeType(node,AST_ASSIGN));
	CPPUNIT_ASSERT_EQUAL(true,myAST.matchesNodeType(node2,AST_PLUS));
	CPPUNIT_ASSERT_EQUAL(false,myAST.matchesNodeType(node2,AST_ASSIGN));
}
void ASTTest::testGetContentStoredIn(){
	AST myAST = AST::AST();
	TreeNode* node = myAST.createTreeNode(AST_PROCEDURE);
	TreeNode* node2 = myAST.createTreeNode(AST_PLUS, 1);
	CPPUNIT_ASSERT_EQUAL(-1,myAST.getContentStoredIn(node));
	CPPUNIT_ASSERT_EQUAL(1,myAST.getContentStoredIn(node2));
}